<?php
/* 
    Created on : 2016-3-18, 10:06:25
    Author     : dongtao <dongtao@xiaomi.com>
*/
class  BaseController extends Controller{
    public $_cookie;
    public $is_login;
    public $assign;
    public $thead;
    public $cookie;
            
     function __construct() {
        parent::__construct();
        date_default_timezone_set('PRC');
        
        $module = Input::getString("m", "index-index");
        $method = Input::getString('do', "index");
        $module_new = explode("-", $module);
        
        //获取cookie
        $this->_cookie = Cookie::getInstance();
        $user = $this->_cookie->get('user');
        if($user){
            $this->cookie = json_decode($user);
        }  else {
            //未登录跳转
            if(strtolower($module) != 'index-index') {
                header('location:?m=index-Index&do=index');
                exit;
            }
        }
        
        //header
        $header = Loader::loadCfg('header');
        $this->assign['action'] = lcfirst($module_new[1]);
        $this->assign['method'] = lcfirst($method);
        $this->assign['header'] = isset($header[$this->assign['action']])?$header[$this->assign['action']]:'';
        
        //thead
        $this->thead = Loader::loadCfg('thead');
        $this->assign['thead'] = isset($this->thead[$this->assign['action'].'_'.$this->assign['method']])?$this->thead[$this->assign['action'].'_'.$this->assign['method']]:'';
    }
    
    public function jsonMsg($code, $msg = '', $ext = '', $is_die = true)
    {
        echo json_encode(array("code" => $code, "message" => $msg, "ext" => $ext));
        $is_die && exit();
    }
    
}


